/**
 * Copyright(c) Yystar Technology Co.,Ltd
 * project：betting-api
 * package：com.yystar.bettingapi.common.util
 * fileName：DegistUtil.java
 * date：2013-4-12
 */
package com.yystar.security.support.util;

import java.security.MessageDigest;

/**
 * @author Jacky Wang
 * @date 2013-4-12
 * @todo TODO
 * @modify <BR>
 *         1.2013-4-12 Jacky Wang Create file.
 */
public class DegistUtil {
		
	/**
	 * The encrypted function using MD5 (32 bytes & lower case)
	 * @param originalText
	 * @return
	 * @throws Exception
	 */
	public static String digestMD5(String originalText) {
		byte buf[] = originalText.getBytes();
		StringBuffer hexString = new StringBuffer();
		String result = "";
		String digit = "";

		try {
			MessageDigest algorithm = MessageDigest.getInstance("MD5");
			algorithm.reset();
			algorithm.update(buf);

			byte[] digest = algorithm.digest();

			for (int i = 0; i < digest.length; i++) {
				digit = Integer.toHexString(0xFF & digest[i]);

				if (digit.length() == 1) {
					digit = "0" + digit;
				}

				hexString.append(digit);
			}

			result = hexString.toString();
		} catch (Exception ex) {
			ex.printStackTrace();
			result = "";
		}

		return result;
	}
	
	public static void main(String[] args) {
		String encryptStr = DegistUtil.digestMD5("asdfasdfasdf");
		System.out.println(encryptStr);
	}
}
